<?php


namespace App\Admin\Controllers;

use SmallRuralDog\Admin\Components\Grid\Tag;
use SmallRuralDog\Admin\Controllers\AdminController;
use SmallRuralDog\Admin\Grid;
use App\Models\OrderLog;

class OrderLogController extends AdminController
{

    public function grid()
    {
        $grid = new Grid(new OrderLog());

        $grid->defaultSort('id', 'desc');

        $grid->column('id', "日志ID")->width(150)->sortable();

        $grid->column('order_bn', "订单编号")->width(150)->sortable();

        $grid->column('source', "来源")->width(100)->align("center")->customValue(function ($row, $value) {
            $source = ['admin'=>'管理员', 'member'=>'会员'];
            return $source[$value];
        });

        $grid->column('op_name', '操作人名称')->width(150);

        $grid->column('behavior', '行为')->width(100)->align("center")->customValue(function ($row, $value) {
            return OrderLog::getBehaviorName($value);
        })->component(Tag::make()->type(["订单创建" => "warning", "订单支付"=>"success", "订单发货" => "success", "订单作废" => "danger", "订单完成"=>'info']));

        $grid->column('status', "状态")->width(100)->align("center")->customValue(function ($row, $value) {
            $status = ['success'=>'执行成功', 'fail'=>'执行失败'];
            return $status[$value];
        })->component(Tag::make()->type(["执行成功" => "success", "执行失败" => "danger"]));


        $grid->column('content', '日志说明');

        $grid->column('created_at', '时间')->width(150)->sortable();

        // 快速搜索
        $grid->quickSearch(['order_bn']);

        $grid->quickSearchPlaceholder("请输入订单号");

        $grid->actionLabel(''); // 隐藏操作

        $grid->actions(function (Grid\Actions $actions){

            $actions->hideDeleteAction(); // 隐藏删除操作
            $actions->hideEditAction(); // 隐藏编辑操作

        })->toolbars(function (Grid\Toolbars $toolbars)
        {
            $toolbars->hideCreateButton();
        });

        return $grid;
    }

}
